package com.cloudcc.boot.utils.util;

import com.cloudcc.boot.model.UserInfo;
import com.cloudcc.client.CCObject;

import java.util.List;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;

public class ZdUtil {
	public static String userName;
	public static String password;

	public static String findinfo(String khjk, String zdlb,String zdkey){
        ResourceBundle prb = PropertyResourceBundle.getBundle("conf");// 获取配置文件
        String userName = prb.getString("userName");
        String password = prb.getString("password");

        String value="";
        DesEncoder de = DesEncoder.getInstance();
        UserInfo uInfo = new UserInfo(userName, de.setDesString(password));
        CCService cs = new CCService(uInfo);
        if(!zdkey.equals("")&&zdkey!=null) {
            List<CCObject> alist = cs.cquery("xtzdb", "khjk='" + khjk + "'and zdlb='" + zdlb + "'and zdkey='" + zdkey + "'and is_Deleted='0'");
            if (alist.size() > 0) {
                CCObject coInfo = alist.get(0);
                value = nvlEncode(coInfo.get("zdvalue")).toString();
            }
        }
        return value;

    }
    public static String finduser(String ower){
        ResourceBundle prb = PropertyResourceBundle.getBundle("conf");// 获取配置文件
        String userName = prb.getString("userName");
        String password = prb.getString("password");

        String value="";
        DesEncoder de = DesEncoder.getInstance();
        UserInfo uInfo = new UserInfo(userName, de.setDesString(password));
        CCService cs = new CCService(uInfo);
        if(!ower.equals("")) {
            List<CCObject> alist = cs.cquery("ccuser", "id='" + ower + "'and is_Deleted='0'");
            if (alist.size() > 0) {
                CCObject coInfo = alist.get(0);
                value = nvlEncode(coInfo.get("employeenum")).toString();
            }
        }
        return value;
    }
    public static String nvlEncode(Object val) {
        if (val == null) {
            return "";
        } else {
            return String.valueOf(val);
        }
    }
    public static void main(String[] args) {
//  String value=ZdUtil.findinfo("客户接口","客户类别","国际工程");
        String value=ZdUtil.finduser("0052019734B5392TpaYD");
        System.out.println("value==="+value);
    }
}
